package gossip.v2.message;

import com.baidu.bjf.remoting.protobuf.annotation.ProtobufClass;
import gossip.v2.cluster.GossipNode;
import lombok.Getter;

import java.util.Map;

// 握手消息
@Getter
@ProtobufClass
public class HandshakeMessage extends GossipMessage {
    // 新增消息类型枚举
    public enum HandshakeType {
        REQUEST,  // 握手请求
        RESPONSE  // 握手响应
    }

    private HandshakeType handshakeType; // 消息类型
    private String ip;
    private int port;
    private Map<String, GossipNode> knownNodes; // 节点ID -> 完整节点信息

    public HandshakeMessage() {
        type = Type.HANDSHAKE;
    }

    public HandshakeMessage(GossipNode sender, Map<String, GossipNode> knownNodes,HandshakeType handshakeType) {
        this();
        this.sender = sender;
        this.senderId = sender != null ? sender.getNodeId() : null;
        assert sender != null;
        this.ip = sender.getIp();
        this.port = sender.getPort();
        this.knownNodes = knownNodes;
        this.handshakeType = handshakeType;
    }
}
